package com.yc;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Controller {

    @GetMapping("/go")
    public String device(HttpServletRequest request) {
        String userAgent = request.getHeader("User-Agent");
        return isMobileDevice(userAgent) ? "手机" : "电脑";
    }

    private boolean isMobileDevice(String userAgent) {
        if (userAgent == null) return false;
        String ua = userAgent.toLowerCase();
        return ua.contains("mobile") || ua.contains("android") || ua.contains("iphone") || ua.contains("ipad") || ua.contains("windows phone");
    }
}
